<template>
  <div class="container">
    <el-form :model="titleRuleForm" :rules="titleRules" ref="titleRuleForm">
      <el-form-item prop="okORno">
        <el-radio-group v-model="titleRuleForm.okORno">
          <el-radio label="1">通过</el-radio>
          <el-radio label="2">拒绝</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item prop="suggestions">
        <el-input
          type="textarea"
          v-model="titleRuleForm.suggestions"
          placeholder="请输入审核意见"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="clearboth">取消</el-button>
        <el-button type="primary" @click="titleOk">确认</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  props: {
    id: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      titleRuleForm: {
        okORno: '1',
        suggestions: ''
      },
      titleRules: {
        suggestions: [
          { required: true, message: '请输入审核意见', trigger: 'blur' },
          { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    clearboth() {
      this.$refs.titleRuleForm.resetFields()
      this.$emit('close')
    },
    titleOk() {
      this.$refs.titleRuleForm.validate(async (valid) => {
        if (valid) {
          const info = {
            id: this.id,
            chkState: this.titleRuleForm.okORno - 0,
            chkRemarks: this.titleRuleForm.suggestions
          }
          const { data } = await choiceCheck(info)
          console.log(data)
          this.$emit('success')
          this.$emit('close')
          this.$message({
            message: '审批成功',
            type: 'success'
          })
        } else {
          this.$message.error('审批失败')
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="less"></style>
